package com.xfcy.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xfcy.blog.common.R;
import com.xfcy.blog.common.constant.SqlConstant;
import com.xfcy.blog.mapper.JobLogMapper;
import com.xfcy.blog.entity.JobLog;
import com.xfcy.blog.service.JobLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 定时任务调度日志表(JobLog)表服务实现类
 *
 * @author 晓风残月Lx
 * @since 2023-04-09 11:03:05
 */
@Service("jobLogService")
public class JobLogServiceImpl extends ServiceImpl<JobLogMapper, JobLog> implements JobLogService {

    /**
     * 定时任务日志列表
     *
     * @param pageNo
     * @param pageSize
     * @param jobGroup
     * @param jobName
     * @param startTime
     * @param status
     * @param endTime
     * @param jobId
     * @return
     */
    @Override
    public R listJobLog(Long pageNo, Long pageSize, String jobName, String jobGroup, String status, String startTime, String endTime, Long jobId) {
        Page<JobLog> jobLogPage = baseMapper.selectPage(new Page<>(pageNo, pageSize), new QueryWrapper<JobLog>()
                .orderByDesc(SqlConstant.CREATE_TIME).eq(jobId != null, SqlConstant.JOB_ID, jobId)
                .like(StringUtils.isNotBlank(jobName), SqlConstant.JOB_NAME, jobName)
                .like(StringUtils.isNotBlank(jobGroup), SqlConstant.JOB_GROUP, jobGroup)
                .eq(StringUtils.isNotBlank(status), SqlConstant.STATUS, status)
                .between(StringUtils.isNotBlank(startTime) && StringUtils.isNotEmpty(endTime), SqlConstant.START_TIME, startTime, endTime));
        return R.success(jobLogPage);
    }
}


